import os,sys

def flist():
    sitelist=[f for f in os.listdir(os.getcwd()) \
        if os.path.isdir(os.path.join(os.getcwd(), f))]
    return sorted(sitelist)

def frename(src,dst):
    try:
        os.rename(src,dst)
    except OSError:
        print 'Error: No such file or directory'

def fcopy(src,dst):
    try:
        os.system("cp -r %s %s" % (src, dst))
    except OSError:
        print 'Error: No such file or directory'
            
    
def fremove(arg):
    os.system("rm -r %s" % (arg))    

def get_data_list(site_name,file_name):
    f = open(site_name+'/'+file_name,'r')
    f.close
    lines = f.readlines()
    
    data=[]; comments=[]
    for line in lines:        
        if line[0]=='#':
            # the line is a comment
            comments.append(line)
            continue        
        data.append(map(int,line.split(',')))    
    return data#, comments

def get_float_data_list(site_name,file_name):
    f = open(site_name+'/'+file_name,'r')
    f.close
    lines = f.readlines()
    
    data=[]; comments=[]
    for line in lines:        
        if line[0]=='#':
            # the line is a comment
            comments.append(line)
            continue        
        data.append(map(float,line.split(',')))
    return data
    
def save_data_list(data,site_name,file_name,comment=' '):
    f = open (site_name+'/'+file_name, 'w')
    for i in data:       
        f.writelines(str(i)[1:-1]+'\n')
    f.close
